//
//  CheLiangListCell.m
//  EnterpriseEdition
//
//  Created by ypj on 2021/10/8.
//

#import "CheLiangListCell.h"
#import "CheLiangModel.h"
@implementation CheLiangListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.carImage createBordersWithColor:nil withCornerRadius:3.0 andWidth:0];
    [self.cancelBtn createBordersWithColor:nil withCornerRadius:2.0 andWidth:0];
}


- (void)setLeaseModel:(CheLiangModel *)leaseModel{
    _leaseModel = leaseModel;
    
    // 图片
    [self.carImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,[NSString urlEncoding:leaseModel.car45Url]]] placeholderImage:Image(@"default_icon")];
    // 车牌号码
    self.paiZhaoLb.text = leaseModel.carNum;
    // 品牌型号
    self.pinPaiLb.text = [NSString stringWithFormat:@"%@%@",leaseModel.carBrand,leaseModel.carMode];
    // 车辆类型
    self.carTypeLb.text = [Tool getId:leaseModel.leaseCarType DicDataWithKey:k_CLLX];
    self.label1Const.constant =  [NSString getLabelOptimumWidth:self.carTypeLb WithFont:11] + 3;
    
    
    self.platformLab.text = [Tool getId:leaseModel.operPlatform DicDataWithKey:k_YXPT];
    self.label2Const.constant = [NSString getLabelOptimumWidth:self.platformLab WithFont:11] + 3;
    
    /**1:未出租  2:出租中  3:已出租 */
    
    // 未出租
    if ([leaseModel.hireFlag intValue] == 0) {
        
        self.priceLb.font = Fond11;
        self.priceLb.textColor = ColorWithAAAAAA;
        self.priceLb.text = [NSString stringWithFormat:@"已闲置:%@天",leaseModel.freeTime];
        [self.priceLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:leaseModel.freeTime size:16];
        self.timeLb.width = 10;
        self.timeLb.text = @"";
        
        NSString *energyTypeStr = @"";
        if(leaseModel.energyType==1){
            energyTypeStr = @"纯动力";
        }
        else if(leaseModel.energyType==2){
            energyTypeStr = @"混合动力";
        }
        else if(leaseModel.energyType==3){
            energyTypeStr = @"燃油动力";
        }
        self.zuHuLb.textColor = ColorWithAAAAAA;
        self.zuHuLb.text = [NSString stringWithFormat:@"%@年丨%@丨%@Km",[NSString stringWithNull:!StringIsEmpty(leaseModel.registerTime)?[leaseModel.registerTime substringToIndex:4]:@""],energyTypeStr,[NSString stringWithNull:leaseModel.kilometers]];
        self.statusLb.textColor = ColorWithEA545A;
        self.statusLb.text = @"未出租";
        self.cancelBtn.hidden = NO;
        [self.cancelBtn setBackgroundColor:mainColor];
        [self.cancelBtn setTitle:@"发布" forState:UIControlStateNormal];
        [self.cancelBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        
        
    }
    
    // 出租中
    else if ([leaseModel.hireFlag intValue] == 1){
      
        self.priceLb.font = Fond14;
        self.priceLb.text = [NSString stringWithFormat:@"%.2lf元/月",[leaseModel.hireMoney doubleValue]];
        self.priceLb.textColor = [UIColor colorWithHexString:@"#EA545A"];
        
        [self.priceLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"元/月"] size:11];
        
        
        self.timeLb.text = [NSString stringWithFormat:@"已发布%@天",leaseModel.timeDay];
        [self.timeLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"%@",leaseModel.timeDay]];
        
        
        NSString *energyTypeStr = @"";
        if(leaseModel.energyType==1){
            energyTypeStr = @"纯动力";
        }
        else if(leaseModel.energyType==2){
            energyTypeStr = @"混合动力";
        }
        else if(leaseModel.energyType==3){
            energyTypeStr = @"燃油动力";
        }
        self.zuHuLb.textColor = ColorWithAAAAAA;
        self.zuHuLb.text = [NSString stringWithFormat:@"%@年丨%@丨%@Km",[NSString stringWithNull:!StringIsEmpty(leaseModel.registerTime)?[leaseModel.registerTime substringToIndex:4]:@""],energyTypeStr,[NSString stringWithNull:leaseModel.kilometers]];
        
        
        self.statusLb.text = @"出租中";
        self.statusLb.textColor = mainColor;
        self.cancelBtn.hidden = NO;
        [self.cancelBtn setBackgroundColor:ColorWithF5F5F5];
        [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [self.cancelBtn setTitleColor:ColorWithAAAAAA forState:UIControlStateNormal];
    
    }
    
    // 已出租
    else if ([leaseModel.hireFlag intValue] == 2){
      
        self.priceLb.font = Fond14;
        self.priceLb.text = [NSString stringWithFormat:@"%.2lf元/月",[leaseModel.rent doubleValue]];
        self.priceLb.textColor = [UIColor colorWithHexString:@"#EA545A"];
        [self.priceLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"%@元/月",leaseModel.rent] size:11];
        
        
        self.timeLb.text = [NSString stringWithFormat:@"剩余租期%@期",@(leaseModel.leftPeriods)];
        [self.timeLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"%@",@(leaseModel.leftPeriods)]];
        
        
      
        self.zuHuLb.textColor = mainColor;
        self.zuHuLb.text = [NSString stringWithFormat:@"客户：%@丨负责人：%@",[NSString stringWithNull:leaseModel.customerName],[NSString stringWithNull:leaseModel.userNameSale]];
        
        self.statusLb.text = @"已出租";
        self.statusLb.textColor = ColorWithAAAAAA;
        self.cancelBtn.hidden = YES;
    
    }
    

}

- (void)setSellModel:(CheLiangModel *)sellModel{
    _sellModel = sellModel;
    
    
    // 图片
    [self.carImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,[NSString urlEncoding:sellModel.car45Url]]] placeholderImage:Image(@"default_icon")];
    // 车牌号码
    self.paiZhaoLb.text = sellModel.carNum;
    // 品牌型号
    self.pinPaiLb.text = [NSString stringWithFormat:@"%@%@",sellModel.carBrand,sellModel.carMode];
    // 车辆类型
    self.carTypeLb.hidden = YES;
    self.platformLab.hidden = YES;
//    self.carTypeLb.text = sellModel.leaseCarType;
//    CGSize size1 = [self.carTypeLb.text sizeWithFont:[UIFont systemFontOfSize:11]];
//    self.label1Const.constant = size1.width + 5;
//
//    self.platformLab.text = sellModel.operPlatform;
//    CGSize size2 = [self.platformLab.text sizeWithFont:[UIFont systemFontOfSize:11]];
//    self.label2Const.constant = size2.width + 5;
    
    /**未出售 5：出售中  6 已出售*/
    
    // 未出售
    if ([sellModel.saleFlag intValue] == 0) {
        
        self.zuHuLb.font = Fond10;
        self.zuHuLb.textColor = Color333;
        self.zuHuLb.text = [NSString stringWithFormat:@"已闲置:%@天",sellModel.freeTime];
        [self.zuHuLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:sellModel.freeTime size:16];
        
        self.timeLb.text = @"";
        
        NSString *energyTypeStr = @"";
        if(sellModel.energyType==1){
            energyTypeStr = @"纯动力";
        }
        else if(sellModel.energyType==2){
            energyTypeStr = @"混合动力";
        }
        else if(sellModel.energyType==3){
            energyTypeStr = @"燃油动力";
        }
        self.priceLb.textColor = ColorWithAAAAAA;
        self.priceLb.font = Fond10;
        self.priceLb.text = [NSString stringWithFormat:@"%@年|%@|%@Km",[NSString stringWithNull:!StringIsEmpty(sellModel.registerTime)?[sellModel.registerTime substringToIndex:4]:@""],energyTypeStr,[NSString stringWithNull:sellModel.kilometers]];
        
        self.statusLb.text = @"未出售";
        self.cancelBtn.hidden = NO;
        [self.cancelBtn setBackgroundColor:mainColor];
        [self.cancelBtn setTitle:@"发布" forState:UIControlStateNormal];
        [self.cancelBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        
        
    }
    
    // 出售中
    else if ([sellModel.saleFlag intValue] == 1){
      
        self.priceLb.font = Fond11;
        self.priceLb.textColor = ColorWithAAAAAA;
        NSString *firstPay = [NSString stringWithFormat:@"%.2lf",[sellModel.firstPay doubleValue]];
        NSString *monthPay = [NSString stringWithFormat:@"%.2lf",[sellModel.monthPay doubleValue]];
        NSString *hireMode = [Tool toolWithHireMode:sellModel.hireMode];
        self.priceLb.text = [NSString stringWithFormat:@"首付%@元/%@|%@供%@元/%@",firstPay,hireMode,hireMode,monthPay,hireMode];
        [self.priceLb addAttributesArray:@[@{NSForegroundColorAttributeName:ColorWithEA545A},@{NSForegroundColorAttributeName:ColorWithEA545A}] forStringArray:@[firstPay,monthPay] size:0];
        
        self.timeLb.text = @"";
        
        self.zuHuLb.textColor = ColorWithAAAAAA;
        self.zuHuLb.text = [NSString stringWithFormat:@"已发布%@天 期数%@期",sellModel.timeDay,[NSString stringWithNull:sellModel.payCount]];
        
        [self.zuHuLb addAttributesArray:@[@{NSForegroundColorAttributeName:ColorWithEA545A},@{NSForegroundColorAttributeName:ColorWithEA545A}] forStringArray:@[sellModel.timeDay,sellModel.payCount] size:0];

        
        self.statusLb.text = @"出售中";
        self.statusLb.textColor = mainColor;
        self.cancelBtn.hidden = NO;
        [self.cancelBtn setBackgroundColor:ColorWithF5F5F5];
        [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [self.cancelBtn setTitleColor:ColorWithAAAAAA forState:UIControlStateNormal];
    
    }
    
    // 已出售
    else if ([sellModel.saleFlag intValue] == 2){
      
        // 全款
        if (sellModel.signType==1) {
            self.priceLb.font = Fond14;
            self.priceLb.text = [NSString stringWithFormat:@"全款%@",[Tool toolWithConversion_W:sellModel.priceSum]];
            self.priceLb.textColor = [UIColor colorWithHexString:@"#EA545A"];
            self.timeLb.text = @"";
            
        }
        else {
            self.priceLb.font = Fond14;
            self.priceLb.text = [NSString stringWithFormat:@"%@元/月",[Tool stringChangeMoneyWithStr:sellModel.rent]];
            self.priceLb.textColor = [UIColor colorWithHexString:@"#EA545A"];
            [self.priceLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"元/%@",[Tool toolWithHireMode:sellModel.hireMode]] size:11];
            
            
            self.timeLb.text = [NSString stringWithFormat:@"剩余租期%@期",@(sellModel.leftPeriods)];
            [self.timeLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"%@",@(sellModel.leftPeriods)]];
        }
      
        
      
        self.zuHuLb.textColor = mainColor;
        self.zuHuLb.text = [NSString stringWithFormat:@"客户：%@丨负责人：%@",[NSString stringWithNull:sellModel.customerName],[NSString stringWithNull:sellModel.userNameSale]];
        
        self.statusLb.text = @"已出售";
        self.statusLb.textColor = ColorWithAAAAAA;
        self.cancelBtn.hidden = YES;
    
    }
    
    
}
- (void)setAllModel:(CheLiangModel *)allModel{
    _allModel = allModel;
    // 图片
    [self.carImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,[NSString urlEncoding:allModel.car45Url]]] placeholderImage:Image(@"default_icon")];
    // 车牌号码
    self.paiZhaoLb.text = allModel.carNum;
    // 品牌型号
    self.pinPaiLb.text = [NSString stringWithFormat:@"%@%@",allModel.carBrand,allModel.carMode];
    // 车辆类型
    self.carTypeLb.text = [Tool getId:allModel.leaseCarType DicDataWithKey:k_CLLX];
    self.label1Const.constant = [NSString getLabelOptimumWidth:self.carTypeLb WithFont:11] + 3;

    self.platformLab.text = [Tool getId:allModel.operPlatform DicDataWithKey:k_YXPT];
    self.label2Const.constant = [NSString getLabelOptimumWidth:self.platformLab WithFont:11] + 3;
    
    // 已出租
    if ([allModel.hireFlag intValue] == 2){
      
        self.priceLb.font = Fond14;
        self.priceLb.text = [NSString stringWithFormat:@"%.2lf元/%@",[allModel.rent doubleValue],[Tool toolWithHireMode:allModel.hireMode]];
        self.priceLb.textColor = [UIColor colorWithHexString:@"#EA545A"];
        [self.priceLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"元/%@",allModel.rent] size:11];
        
        
        self.timeLb.text = [NSString stringWithFormat:@"剩余租期%@期",@(allModel.leftPeriods)];
        [self.timeLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"%@",@(allModel.leftPeriods)]];
        
        
      
        self.zuHuLb.textColor = mainColor;
        self.zuHuLb.text = [NSString stringWithFormat:@"客户：%@丨负责人：%@",[NSString stringWithNull:allModel.customerName],[NSString stringWithNull:allModel.userNameSale]];
        
        self.statusLb.hidden = NO;
        self.statusLb.text = @"已出租";
        self.statusLb.textColor = ColorWithAAAAAA;
        self.cancelBtn.hidden = YES;
    
    }
    // 已出售
    else if ([allModel.saleFlag intValue] == 2){
      
        
        // 全款
        if (allModel.signType==1) {
            self.priceLb.font = Fond14;
            self.priceLb.text = [NSString stringWithFormat:@"全款%@",[Tool toolWithConversion_W:allModel.priceSum]];
            self.priceLb.textColor = [UIColor colorWithHexString:@"#EA545A"];
            self.timeLb.text = @"";
            
        }
        else{
            self.priceLb.font = Fond14;
            self.priceLb.text = [NSString stringWithFormat:@"%.2lf元/月",[allModel.rent doubleValue]];
            self.priceLb.textColor = [UIColor colorWithHexString:@"#EA545A"];
            [self.priceLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"元/%@",[Tool toolWithHireMode:allModel.hireMode]] size:11];
            
            
            self.timeLb.text = [NSString stringWithFormat:@"剩余租期%@期",@(allModel.leftPeriods)];
            [self.timeLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"%@",@(allModel.leftPeriods)]];
        }
        
        
       
        
        
      
        self.zuHuLb.textColor = mainColor;
        self.zuHuLb.text = [NSString stringWithFormat:@"客户：%@丨负责人：%@",[NSString stringWithNull:allModel.customerName],[NSString stringWithNull:allModel.userNameSale]];
        
        self.statusLb.hidden = NO;
        self.statusLb.text = @"已出售";
        self.statusLb.textColor = ColorWithAAAAAA;
        self.cancelBtn.hidden = YES;
    
    }
    
    // 未出租
   else  {
        
       
       NSString *energyTypeStr = @"";
       if(allModel.energyType==1){
           energyTypeStr = @"纯动力";
       }
       else if(allModel.energyType==2){
           energyTypeStr = @"混合动力";
       }
       else if(allModel.energyType==3){
           energyTypeStr = @"燃油动力";
       }
       
       
       self.zuHuLb.font = Fond11;
       self.zuHuLb.textColor = ColorWithAAAAAA;
       self.zuHuLb.text = [NSString stringWithFormat:@"%@年丨%@丨%@Km",[NSString stringWithNull:!StringIsEmpty(allModel.registerTime)?[allModel.registerTime substringToIndex:4]:@""],energyTypeStr,[NSString stringWithNull:allModel.kilometers]];
       
//        self.priceLb.font = Fond11;
//        self.priceLb.text = [NSString stringWithFormat:@"已空闲:%@天",allModel.timeDay];
//        [self.priceLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:allModel.timeDay size:16];
        
       self.timeLb.text = @"";
        self.priceLb.text = @"";
//        self.zuHuLb.text = @"";
        self.statusLb.hidden = YES;
        self.cancelBtn.hidden = YES;
    }
    
//    // 出租中
//    else if ([allModel.hireFlag intValue] == 1){
//
//        self.priceLb.font = Fond14;
//        self.priceLb.text = [NSString stringWithFormat:@"%.2lf元/%@",[allModel.hireMoney doubleValue],allModel.hireMode];
//        self.priceLb.textColor = [UIColor colorWithHexString:@"#EA545A"];
//
//        [self.priceLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"元/%@",allModel.hireMode] size:11];
//
//
//        self.timeLb.text = [NSString stringWithFormat:@"已发布%@天",allModel.timeDay];
//        [self.timeLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:[NSString stringWithFormat:@"%@",@(allModel.leftPeriods)]];
//
//
//        NSString *energyTypeStr = @"";
//        if(allModel.energyType==1){
//            energyTypeStr = @"纯动力";
//        }
//        else if(allModel.energyType==2){
//            energyTypeStr = @"混合动力";
//        }
//        else if(allModel.energyType==3){
//            energyTypeStr = @"燃油动力";
//        }
//        self.zuHuLb.textColor = ColorWithAAAAAA;
//        self.zuHuLb.text = [NSString stringWithFormat:@"%@年|%@|%@公里",[NSString stringWithNull:!StringIsEmpty(allModel.registerTime)?[allModel.registerTime substringToIndex:4]:@""],energyTypeStr,[NSString stringWithNull:allModel.kilometers]];
//
//
//        self.statusLb.hidden = YES;
//        self.cancelBtn.hidden = YES;
//
//    }
//
//
//    // 未出售
//   else if ([allModel.saleFlag intValue] == 0) {
//
//        self.zuHuLb.font = Fond10;
//        self.zuHuLb.textColor = Color333;
//        self.zuHuLb.text = [NSString stringWithFormat:@"已闲置:%@天",allModel.timeDay];
//        [self.zuHuLb addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#EA545A"]} forString:allModel.timeDay size:16];
//
//        self.timeLb.text = @"";
//
//        NSString *energyTypeStr = @"";
//        if(allModel.energyType==1){
//            energyTypeStr = @"纯动力";
//        }
//        else if(allModel.energyType==2){
//            energyTypeStr = @"混合动力";
//        }
//        else if(allModel.energyType==3){
//            energyTypeStr = @"燃油动力";
//        }
//        self.priceLb.textColor = ColorWithAAAAAA;
//        self.priceLb.font = Fond10;
//        self.priceLb.text = [NSString stringWithFormat:@"%@年|%@|%@公里",[NSString stringWithNull:!StringIsEmpty(allModel.registerTime)?[allModel.registerTime substringToIndex:4]:@""],energyTypeStr,[NSString stringWithNull:allModel.kilometers]];
//
//       self.statusLb.hidden = YES;
//       self.cancelBtn.hidden = YES;
//
//
//    }
//
//    // 出售中
//    else if ([allModel.saleFlag intValue] == 1){
//
//        self.priceLb.font = Fond11;
//        self.priceLb.textColor = ColorWithAAAAAA;
//        NSString *firstPay = [NSString stringWithFormat:@"%.2lf",[allModel.firstPay doubleValue]];
//        NSString *monthPay = [NSString stringWithFormat:@"%.2lf",[allModel.monthPay doubleValue]];
//        self.priceLb.text = [NSString stringWithFormat:@"首付%@元/%@|月供%@元/月",firstPay,allModel.hireMode,monthPay];
//        [self.priceLb addAttributesArray:@[@{NSForegroundColorAttributeName:ColorWithEA545A},@{NSForegroundColorAttributeName:ColorWithEA545A}] forStringArray:@[firstPay,monthPay] size:0];
//
//        self.timeLb.text = @"";
//
//        self.zuHuLb.textColor = ColorWithAAAAAA;
//        self.zuHuLb.text = [NSString stringWithFormat:@"已发布%@天 期数%@期",allModel.timeDay,[NSString stringWithNull:allModel.payCount]];
//
//        [self.zuHuLb addAttributesArray:@[@{NSForegroundColorAttributeName:ColorWithEA545A},@{NSForegroundColorAttributeName:ColorWithEA545A}] forStringArray:@[allModel.timeDay,allModel.payCount] size:0];
//
//
//        self.statusLb.hidden = YES;
//        self.cancelBtn.hidden = YES;
//
//    }
    
    
}
+(NSString *)reuseIdentifier{
    return @"CheLiangListCell";
}
@end
